﻿using AutoMapper;
using EFGetStarted;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using ZFY.AspNetCore;
using ZFY.Core;
using ZFY.UnitOfWork.Interface;

namespace BlogApi.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
   
        public WeatherForecastController(IBlogSerivce blogSerivce, ILogger<WeatherForecastController> logger)
        {
            _blogSerivce = blogSerivce;
            _logger = logger;
        }
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IBlogSerivce _blogSerivce;

        [HttpPut]
        public async Task<ZFYReponse<bool>> CreateAsync()
        {
            
            await _blogSerivce.Create(new Blog { Url = "1231" });
            return new ZFYReponse<bool>() { Data = true };
        }
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
    public class Dto
    {
        [Required]
        public string test { get; set; }
    }
}
